<%-- 
    Document   : DoLoginAdmin
    Created on : 17-mag-2014, 17.52.09
    Author     : Albo
--%>

<%@page import="java.sql.ResultSet"%>
<%@page import="java.sql.Statement"%>
<%@page import="java.sql.DriverManager"%>
<%@page import="java.sql.Connection"%>
<%@page import="it.polimi.Mir_1.paw.DBconnect"%>
<%@page import="it.polimi.Mir_1.paw.AccessoUtentiRegistrati"%>

<%
    String username=request.getParameter("username");
    String password=request.getParameter("password"); 
    out.print(username+" "+password);
          DBconnect connAlbo = new DBconnect();
       // CONNESSIONE AL DATABASE
       Connection conn = connAlbo.getConnection();
       AccessoUtentiRegistrati user =null;
       try{
        user=connAlbo.login(username,password, conn);
       }catch(Exception e){
           e.printStackTrace();
       }
       
       String utente="";
       if (user!=null){
           utente= user.getUsername();
                out.print("utente Loggato.");
                if (user.getRuolo().equals("Admin")){
           %><jsp:forward page="PaginaAdmin.jsp"/>
<%
                }else{
                    
                    %>
                    <jsp:forward page="PaginaUtente.jsp">
                        <jsp:param name="user" value="<%=utente%>"></jsp:param>
                    </jsp:forward>
<%
               }
            
                }else {
                        out.print("utente non loggato");
                %>
                <jsp:forward page="PaginaDiaccesso.jsp?err=utente o pw sbagliati"/>
<%}
            conn.close();
%>


